package com.haoqi.document.template.web;

import com.haoqi.document.template.base.BaseController;
import com.haoqi.document.template.base.IBaseResult;
import com.haoqi.document.template.base.IBaseResultUtils;
import com.haoqi.document.template.dto.in.ExcelExportWithUrlReqDtoIn;
import com.haoqi.document.template.dto.in.WordExportWithUrlReqDtoIn;
import com.haoqi.document.template.service.ExcelExportService;
import com.haoqi.document.template.service.WordExportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/document/template"})
public class DocumentTemplateController extends BaseController {

    @Autowired
    private ExcelExportService excelExportService;

    @Autowired
    private WordExportService wordExportService;

    //模板文件url+业务数据，同步导出文件url
    @PostMapping("/excel/export")
    public IBaseResult excelDataExport(@RequestBody @Validated ExcelExportWithUrlReqDtoIn dtoIn, BindingResult result) throws Exception {
        doCheck(result);
        return IBaseResultUtils.success(excelExportService.excelDataExport(dtoIn));
    }

    //模板文件url+业务数据，同步导出文件url
    @PostMapping("/word/export")
    public IBaseResult wordDataExport(@RequestBody @Validated WordExportWithUrlReqDtoIn dtoIn, BindingResult result) throws Exception {
        doCheck(result);
        return IBaseResultUtils.success(wordExportService.wordDataExport(dtoIn));
    }

}